Author: Nicolas Legrand nicolas.legrand@cfin.au.dk
import os
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import plotly.graph_objects as go
import plotly.express as px
from plotly.subplots import make_subplots
from systole.detection import oxi_peaks
from systole.plotly import plot_subspaces, plot_raw
import plotly.io as pio
pio.renderers.default='notebook'
sns.set_context('talk')
Import data
path = 'C:/Users/au646069/ECG/1_VPN_aux/'
subject = 'sub_0019'
# Parameters
subject = "sub_0022"
path = "C:/Users/au646069/ECG/1_VPN_aux/"
resultsFiles = os.listdir(os.path.join(path, subject, 'HBC'))
# Logs dataframe
df = pd.read_csv(os.path.join(path, subject, 'HBC', [file for file in resultsFiles if file.endswith('final.txt')][0]))
df
| nTrial | Reported | Condition | Duration | Confidence | ConfidenceRT | |
|---|---|---|---|---|---|---|
| 0 | 0 | 22 | Count | 30 | 3 | 2.489 |
| 1 | 1 | 24 | Count | 25 | 6 | 2.940 |
| 2 | 2 | 41 | Count | 50 | 3 | 1.595 |
| 3 | 3 | 45 | Count | 45 | 4 | 2.679 |
| 4 | 4 | 36 | Count | 40 | 3 | 1.735 |
| 5 | 5 | 31 | Count | 35 | 2 | 1.207 |
# PPG signal
ppg = {}
for i in range(6):
ppg[str(i)] = np.load(os.path.join(path, subject, 'HBC', f'{subject[4:]}_{i}.npy'))
signal, peaks = oxi_peaks(ppg['0'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[0]} ; Detected : {np.sum(peaks)}')
Reported: 22 ; Detected : 43
signal, peaks = oxi_peaks(ppg['1'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[1]} ; Detected : {np.sum(peaks)}')
Reported: 24 ; Detected : 38
signal, peaks = oxi_peaks(ppg['2'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[2]} ; Detected : {np.sum(peaks)}')
Reported: 41 ; Detected : 69
signal, peaks = oxi_peaks(ppg['3'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[3]} ; Detected : {np.sum(peaks)}')
Reported: 45 ; Detected : 64
signal, peaks = oxi_peaks(ppg['4'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[4]} ; Detected : {np.sum(peaks)}')
Reported: 36 ; Detected : 55
signal, peaks = oxi_peaks(ppg['5'][0])
rr = np.diff(np.where(peaks)[0])
plot_subspaces(rr=rr, height=500)
plot_raw(signal, sfreq=1000)
print(f'Reported: {df.Reported.loc[5]} ; Detected : {np.sum(peaks)}')
Reported: 31 ; Detected : 49